﻿using MaxStoreErp.Core.Exceptions;
using MaxStoreShop.Domain.Directories;
using MaxStoreShop.Logic.Services.Directories;
using MaxStoreShop.Logic.ServicesContracts.Directories;
using MaxStoreShop.Logic.Tests.FakeRepositories;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MaxStoreShop.Logic.Tests
{
    [TestClass]
    public class SupplierServiceTests
    {
        [TestMethod]
        public void DeleteSupplierShouldNormal()
        {
            CreateInstance().DeleteSupplier(new Supplier());
        }

        [TestMethod]
        [ExpectedException(typeof(ErpRuntimeException))]
        public void DeleteSupplierShouldThrowErpRuntimeExceptionIfSupplierIsNull()
        {
            CreateInstance().DeleteSupplier(null);
        }

        [TestMethod]
        public void SaveSupplierShouldNormal()
        {
            CreateInstance().SaveSupplier(new Supplier {Name = "Supplier", Phone = "123"});
        }

        [TestMethod]
        [ExpectedException(typeof(ErpRuntimeException))]
        public void SaveSupplierShouldThrowErpRuntimeExceptionIfSupplierIsNull()
        {
            CreateInstance().SaveSupplier(null);
        }

        [TestMethod]
        [ExpectedException(typeof(ErpRuntimeException))]
        public void SaveSupplierShouldThrowErpRuntimeExceptionIfNameIsEmpty()
        {
            CreateInstance().SaveSupplier(new Supplier {Phone = "123"});
        }

        [TestMethod]
        [ExpectedException(typeof (ErpRuntimeException))]
        public void SaveSupplierShouldThrowErpRuntimeExceptionIfPhoneIsEmpty()
        {
            CreateInstance().SaveSupplier(new Supplier {Name = "Supplier"});
        }

        static ISupplierService CreateInstance()
        {
            return new SupplierService(new SupplierRepositoryFake());
        }
    }
}
